package com.rivercloud.dao.Impl;

import java.io.InputStream;
import java.util.List;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import com.rivercloud.dao.MergeRowDao;
import com.rivercloud.entity.Merge;
import com.rivercloud.entity.MergeRow;

public class MergeRowDaoImpl implements MergeRowDao {
	 static SqlSessionFactory sqlSessionFactory = null;
	 static{
		 SqlSessionFactoryBuilder sessionFactoryBuilder = new SqlSessionFactoryBuilder();
		 InputStream inputStream =null;
		 
		 try {
			inputStream = Resources.getResourceAsStream("SqlMapConfig.xml");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
		sqlSessionFactory = sessionFactoryBuilder.build(inputStream);
	 }
	@Override
	public List<MergeRow> findMergeRowByTableId(Integer tableId) {
		SqlSession session = sqlSessionFactory.openSession();
		List<MergeRow> list = session.selectList("findMergeRowByTableId", tableId);
		
		session.close();
		return list;
	}
	@Override
	public MergeRow findMergeRowByInfo(MergeRow mergeRow) {
		SqlSession session = sqlSessionFactory.openSession();
		MergeRow existMerge = session.selectOne("findMergeRowByInfo", mergeRow);
		
		session.close();
		return existMerge;
	}
	@Override
	public void addMergeBoxRow(MergeRow mergeRow) {
		SqlSession session = sqlSessionFactory.openSession();
		session.insert("addMergeBoxRow",mergeRow);
		session.commit();
		session.close();
	}
	@Override
	public void updateMergeBoxRow(MergeRow mergeRow) {
		SqlSession session = sqlSessionFactory.openSession();
		session.update("updateMergeBoxRow", mergeRow);
		session.commit();
		session.close();
	}
	@Override
	public void deleteMergeRow(MergeRow mergeRow) {
		SqlSession session = sqlSessionFactory.openSession();
		session.delete("deleteMergeRow", mergeRow);
		session.commit();
		session.close();
	}
	@Override
	public void deleteMergeRowByTableId(Integer tableId) {
		SqlSession session = sqlSessionFactory.openSession();
		session.delete("deleteMergeRowByTableId", tableId);
		session.commit();
		session.close();
	}   






}
